//Generates GUID, currently argc = 3
//Taken from WiX tutorial site
#define _OLEAUT32_

#include <stdio.h>
#include <unknwn.h>
#include <string.h>

GUID guid;
WORD* wstrGUID[100];
char strGUID[100];
int count, i;

typedef char String[20];
const String OutputFile = "C:\\Wills\\output.txt";
FILE *fOut;

int main (int argc, char* argv[]) 
{
  if (argc != 2) {
	fprintf (stderr, "SYNTAX: UUIDGEN <number-of-GUIDs-to-generate>\n");
	return 1;
	}
  count = atoi (argv[1]);
  fOut = fopen(OutputFile, "w");
  for (i = 0; i < count; i++) {
	CoCreateGuid (&guid);
	StringFromCLSID (&guid, (LPOLESTR*)wstrGUID);
	WideCharToMultiByte (CP_ACP, 0, *wstrGUID, -1, strGUID, MAX_PATH, NULL, NULL);
	printf ("%s\n", strGUID);
	//prints to fOut
	if (fOut!=NULL)
		fprintf (fOut, "%s\n", strGUID);

	else
		printf("Unable to write to file \n");
	}

  fclose(fOut);
  getchar();

  return 0;
}
